<#if Session.user.rolekind==2 > 
<div id="div.auth.baseinfo.act">
 	<table border=0>
 		<tr><td height=40>操作 ： <span id="tip"/> </td></tr>
 		<tr><td height=40>控制器名称 ：<input type="text" id="actionclass" name="actionclass" size=50 value=""> </td>
 		</tr>
 		<tr><td><div id = "div.auth.baseinfo.act.kind" ></div> </td></tr>
 	</table>
 	<input type="button" id="addAction" name="addAction" value="添加" onclick="actioninsert();">
</div>
<div id="div.auth.baseinfo.actionlist"></div>

<script type="text/javascript">
	var dataURL = '/data/sc.action';
	
	var loadActionClass = function(){
		try {
			var request = new Request.JSON({
				url: dataURL,
				onComplete: function(json,text) {
					var content = '';
						if(null != json.recorders && json.recorders.length>0){
						   content='<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\" >';
						   content += '<tr><td>控制器名</td><td>权限类型</td><td></td></tr>';
					 	   json.recorders.each(function(item, index){
    		 			 		content += '<tr><td>'+item.actionclass+'</td>' +
    		 			 					'<td>' + item.kindname + '</td>' + 
    		 			 				'<td><a href="#" onclick="actiondelete(\''+item.id+'\');">删除</a></td></tr>';
							});
    		 				content += '</table>';
						} 
					$('div.auth.baseinfo.actionlist').set('html',content);
				}
			}).get({"scid":"authaction_1","authid":nodeinfo.id});
		} catch (ex) {
			MUI.notification('<font color=red>错误：</font>访问失败('+ex.message+')');
		}
	}
	
	//-------------填充权限类型 
	var authactionkind=null;

	var loadAuthActionKindList = function(){
		var columns = [{text:'权限代号',name:'kind'},{text:'权限类型',name:'kindname'}];//要显示的字段
		var dataURLParams = {"scid":"auth_action_kind", "authid":nodeinfo.id};
		if (!authactionkind){
			authactionkind = new MUI.List({
				instanceName: 'authactionkind',
		       	container:'div.auth.baseinfo.act.kind',
		       	showCheckBox:true,
				showCommand:false,
		       	id: "authactionkindList",
		       	columns:columns,
		       	dataURL:dataURL,
		       	dataURLParams: dataURLParams,
		       	cbName: 'idsauthactionkind',
		       	saveCheck:true,
		       	commands:[]
		   	});//MUI.List
	   	}
	   	authactionkind.setDataURLParams(dataURLParams);
	   	authactionkind.findList(1,true);
	}
	
	var fillcontent = function(){
		loadActionClass();
		loadAuthActionKindList();
	}

	var actiondelete = function(id){
		try {
			var request = new Request.JSON({
				url: dataURL,
				onComplete: function(json,text) {
					if (json.error.errorcode==0){
		 				MUI.notification('删除成功！');
		 				loadActionClass();
		 			}else{
		 				MUI.notification('<font color=red>错误：</font>('+json.error.retstring+')');
		 			}
				}
			}).get({"scid":"authaction_2","id":id});
		} catch (ex) {
			MUI.notification('<font color=red>错误：</font>访问失败('+ex.message+')');
		}
	}
	
	var actioninsert = function(){
		var actionclass = $('actionclass').get('value');
		if(null==actionclass || ""==actionclass.trim()) {
			MUI.notification('<font color=red>错误：</font>(控制器名必须填写)');
			return;
		}
		var checkids = authactionkind.getcurCheckIds();
		checkids = checkids + "";
		if(null==checkids || ""==checkids) { MUI.notification('<font color=red>错误：</font>(必须选择一项的权限种类)'); return; }
		 
		try {
			var request = new Request.JSON({
				url: dataURL,
				onComplete: function(json,text) {
					if (json.error.errorcode==0){
		 				MUI.notification('添加成功！');
		 				$('actionclass').set('value','');
		 				loadActionClass();
		 				authactionkind.cancelAll();
		 			}else{
		 				MUI.notification('<font color=red>错误：</font>('+json.error.retstring+')');
		 			}
				}
			}).get({"scid":"authaction_3","authid":nodeinfo.id, "actionclass": actionclass, "checkids": checkids});
		} catch (ex) {
			MUI.notification('<font color=red>错误：</font>访问失败('+ex.message+')');
		}
	}
	
	 window.addEvent('domready', function() {
		 new MUI.Require({
		  js: [MUI.path.plugins + 'mochaList/List.js'],
		  onload: function(){
			//nodeinfo 从auth.tree.action的onNodeClick事件传过来的
		 	if(nodeinfo!=null){
				$('tip').set('html', '您正在添加 [ '  + nodeinfo.title + ' ]节点的对应控制器');
			}else{
				$('tip').set('html', '错误 [未取得节点信息] ');
				MUI.notification('<font color=red>错误：</font> 未取得节点信息 ');
				return;
			}
			fillcontent(); 
		  } 
		}); 
	
	 });

</script>
<#else>
您无权访问该页面！
</#if>